// weakMap没有forEach、clear


// 应用场景（vue3响应式原理）
const obj1 = {
  name: "yz",
  age: 18
}

const obj2 = {
  name: "jav zhou",
  height: 1.78,
  address: "北京市"
}

function obj1Name() {
  console.log("obj1Name执行");
}
function obj2Name() {
  console.log("obj2Name执行");
}

// 1.创建weakMap
const weakMap = new WeakMap()

// 2.1 对obj1收集的数据结构
const obj1Map = new Map()
obj1Map.set("name", [obj1Name, obj2Name])
weakMap.set(obj1, obj1Map)

// 2.2 对obj2收集的数据结构
const obj2Map = new Map()
obj2Map.set("name", [obj1Name, obj2Name])
weakMap.set(obj2, obj2Map)

// 3.如果改变
obj1.name = "jay"
const targetMap = weakMap.get(obj1)
const fns = targetMap.get("name")
fns.forEach(item => item());
